package com.o2opuzi.pay.service.impl

import javax.annotation.Resource;
import javax.annotation.Resources;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.asm.Type;
import com.o2opuzi.lib.util.RandomStringUtils;
import com.o2opuzi.lib.util.TradeNoUtils;
import com.o2opuzi.pay.service.PayService;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;

@Service
class PayOrderService {
	
	@Resource(name="alipayService")
	private PayService alipayService;
	@Resource(name = "wxpayService")
	private PayService wxpayService;
	
	/**
	 * 开始支付
	 * @auther Y.hj
	 * @param order
	 * @return
	 */
	@Transactional
	def dopay(Map<String,Object> params){
		def order = [:];
		order["order_no"] = TradeNoUtils.create();
		order["create_time"] = new Date();
		order["status"] = 0;
		order["id"] = payOrderDao.save(order);
		
		String type =  params["type"];
		if(type.equals("wxpay")){
			wxpayService.doPay(order);
		}else if(type.equals("alipay")){
			alipayService.doPay(order);
		}
		 
				
		return order;
	}
	
	/**
	 * 回调
	 * @auther Y.hj
	 * @param params
	 * @param callback
	 * @return
	 */
	def doNotify(Map<String, Object> params,callback){
		String type = params.type;
		String result = "";
		if(type.equals("wxpay")) {
			result = wxpayService.doNotify(params);
		}else if(type.equals("alipay")){
			result = alipayService.doNotify(params);
		}
		return result;
	}
}
